function test_y = fknn(x, test_x, k, num, u)
% x:nxm,test_x:n0xm,test_y:n0x1,
% u:n*num,这个num代表类别,u->menbershiip,k代表最近邻k个
n0 = size(test_x, 1);
m = 2;
% 表示每个样本属于每个类的概率
U = zeros(n0, num);
for i = 1 : n0
    Dist = sum((x - test_x(i, :)).^2,2);
    % 从小大大排序，取前k个
    [D,I] = sort(Dist);
    D = D(1:k, :);
    % 防止除0
    D(D==0) = 0.00001;
    D = D.^(-1 / (m - 1));
    Sum_DIST = sum(D);
    for j = 1 : num
        Sum_MULT = sum(u(I(1:k), j) .* D);
        U(i, j) = Sum_MULT / Sum_DIST;
    end 
end
% 求U每行最大值以及对应的索引
[~, I] = max(U, [], 2);
test_y = I;
end